#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e9+7;
int n,m;
pair<int,int> indexx[305][305];
int nn,mm;
char a[305][305],aa[305][305];
int bl[305][2];
int rk1[305][305],rk2[305][305];
int f1[355][(1<<18)],f2[355][(1<<18)];
int enfalse[(1<<18)];
signed main()
{
    freopen("disanti.in","r",stdin);
    freopen("disanti.out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
            a[i][j]-='0';
        }
    }
    if(n<m)
    {
        nn=m;
        mm=n;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(i<=j)
                {
                    swap(a[i][j],a[j][i]);
                    indexx[i][j]=make_pair(j,i);
                    indexx[j][i]=make_pair(i,j);
                }
            }
        }
    }
    else
    {
        nn=n;
        mm=m;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                indexx[i][j]=make_pair(i,j);
            }
        }
    }
    int cnt=0;
    f1[0][0]=1;
    for(int i=1;i<=nn;i++)
    {
        for(int j=0;j<=mm;j++)
        {
            rk1[i][j]=++cnt;
            int ii=rk1[i][j];
            if(j==0)
            {
                for(int k=0;k<(1<<(mm+1));k++)
                {
                    if(k&(1<<mm))
                    {
                        continue;
                    }
                    f1[ii][k*2]+=f1[ii-1][k];
                }
            }
            else
            {
                for(int k=0;k<(1<<(mm+1));k++)
                {
                    int tt1=k&(1<<(j-1)),tt2=k&(1<<j);
                    if(tt1&&tt2)
                    {
                        continue;
                    }
                    if(tt1)
                    {
                        if(a[i][j]==a[i][j-1])
                        {
                            f1[ii][k-tt1+(1<<j)]+=f1[ii-1][k];
                            f1[ii][k-tt1+(1<<j)]%=N;
                            f1[ii][k-tt1]+=f1[ii-1][k];
                            f1[ii][k-tt1]%=N;
                        }
                    }
                    else if(tt2)
                    {
                        if(a[i][j]==a[i-1][j])
                        {
                            f1[ii][k-tt2+(1<<(j-1))]+=f1[ii-1][k];
                            f1[ii][k-tt2+(1<<(j-1))]%=N;
                            f1[ii][k-tt2]+=f1[ii-1][k];
                            f1[ii][k-tt2]%=N;
                        }
                    }
                    else
                    {
                        f1[ii][k+(1<<(j-1))]+=f1[ii-1][k];
                        f1[ii][k+(1<<(j-1))]%=N;
                        f1[ii][k+(1<<j)]+=f1[ii-1][k];
                        f1[ii][k+(1<<j)]%=N;
                        f1[ii][k]+=f1[ii-1][k];
                        f1[ii][k]%=N;
                    }
                }
            }
        }
    }
    for(int i=1;i<=nn;i++)
    {
        for(int j=1;j<=mm;j++)
        {
            aa[i][j]=a[nn-i+1][mm-j+1];
        }
    }
    int cnt2=0;
    f2[0][0]=1;
    for(int i=1;i<=nn;i++)
    {
        for(int j=0;j<=mm;j++)
        {
            rk2[i][j]=++cnt2;
            int ii=rk2[i][j];
            if(j==0)
            {
                for(int k=0;k<(1<<(mm+1));k++)
                {
                    if(k&(1<<mm))
                    {
                        continue;
                    }
                    f2[ii][k*2]+=f2[ii-1][k];
                }
            }
            else
            {
                for(int k=0;k<(1<<(mm+1));k++)
                {
                    int tt1=k&(1<<(j-1)),tt2=k&(1<<j);
                    if(tt1&&tt2)
                    {
                        continue;
                    }
                    if(tt1)
                    {
                        if(aa[i][j]==aa[i][j-1])
                        {
                            f2[ii][k-tt1+(1<<j)]+=f2[ii-1][k];
                            f2[ii][k-tt1+(1<<j)]%=N;
                            f2[ii][k-tt1]+=f2[ii-1][k];
                            f2[ii][k-tt1]%=N;
                        }
                    }
                    else if(tt2)
                    {
                        if(aa[i][j]==aa[i-1][j])
                        {
                            f2[ii][k-tt2+(1<<(j-1))]+=f2[ii-1][k];
                            f2[ii][k-tt2+(1<<(j-1))]%=N;
                            f2[ii][k-tt2]+=f2[ii-1][k];
                            f2[ii][k-tt2]%=N;
                        }
                    }
                    else
                    {
                        f2[ii][k+(1<<(j-1))]+=f2[ii-1][k];
                        f2[ii][k+(1<<(j-1))]%=N;
                        f2[ii][k+(1<<j)]+=f2[ii-1][k];
                        f2[ii][k+(1<<j)]%=N;
                        f2[ii][k]+=f2[ii-1][k];
                        f2[ii][k]%=N;
                    }
                }
            }
        }
    }
    for(int i=0;i<(1<<(mm+1));i++)
    {
        for(int j=0;j<=mm;j++)
        {
            if(i&(1<<j))
            {
                enfalse[i]+=(1<<(mm-j));
            }
        }
        //cout<<"~~"<<i<<" "<<enfalse[i]<<endl;
    }
    for(int it=1;it<=n;it++)
    {
        for(int jt=1;jt<=m;jt++)
        {
            int ii=indexx[it][jt].first,jj=indexx[it][jt].second;
            //cout<<"!!"<<it<<" "<<jt<<" "<<ii<<" "<<jj<<endl;
            a[ii][jj]=1-a[ii][jj];
            int ans=0;
            int i1=rk1[ii][jj]-1,i2=rk2[nn-ii+1][mm-jj+1]-1;
            int incl=0;
            for(int j=1;j<jj;j++)
            {
                if(a[ii][j]!=a[ii+1][j])
                {
                    incl+=(1<<(j-1));
                }
            }
            for(int j=jj+1;j<=mm;j++)
            {
                if(a[ii-1][j]!=a[ii][j])
                {
                    incl+=(1<<j);
                }
            }
            //cout<<"~~"<<ii<<" "<<jj<<" "<<incl<<endl;
            for(int k=0;k<(1<<(mm+1));k++)
            {
                int tt1=k&(1<<(jj-1)),tt2=k&(1<<jj);
                if(tt1&&tt2)
                {
                    continue;
                }
                if(((k-tt1-tt2)&incl)!=0)
                {
                    continue;
                }
                if(f1[i1][k]==0)
                {
                    continue;
                }
                //cout<<"!!"<<k<<endl;
                if(tt1)
                {
                    if(a[ii][jj]==a[ii][jj-1])
                    {
                        int kt=k-tt1+(1<<jj);
                        if(a[ii][jj+1]==a[ii][jj])
                        {
                            ans+=f1[i1][k]*f2[i2][enfalse[kt]]%N;
                        }
                        kt=k-tt1;
                        ans+=f1[i1][k]*f2[i2][enfalse[kt]]%N;
                    }
                }
                else if(tt2)
                {
                    if(a[ii][jj]==a[ii-1][jj])
                    {
                        int kt=k-tt2+(1<<(jj-1));
                        if(a[ii+1][jj]==a[ii][jj])
                        {
                            ans+=f1[i1][k]*f2[i2][enfalse[kt]]%N;
                        }
                        kt=k-tt2;
                        ans+=f1[i1][k]*f2[i2][enfalse[kt]]%N;
                    }
                }
                else
                {
                    int kt=k+(1<<jj);
                    if(a[ii][jj+1]==a[ii][jj])
                    {
                        //cout<<"%%"<<kt<<" "<<i2<<" "<<f2[i2][enfalse[kt]]<<endl;
                        ans+=f1[i1][k]*f2[i2][enfalse[kt]]%N;
                    }
                    kt=k+(1<<(jj-1));
                    if(a[ii+1][jj]==a[ii][jj])
                    {
                        //cout<<"%%"<<kt<<" "<<f2[i2][enfalse[kt]]<<endl;
                        ans+=f1[i1][k]*f2[i2][enfalse[kt]]%N;
                    }
                    kt=k;
                    //cout<<"%%"<<kt<<" "<<f2[i2][enfalse[kt]]<<endl;
                    ans+=f1[i1][k]*f2[i2][enfalse[kt]]%N;
                }
                ans%=N;
            }
            cout<<ans<<" ";
            a[ii][jj]=1-a[ii][jj];
        }
        cout<<endl;
    }
    return 0;
}
